<?php
namespace app\index\controller;
use frame\lib\Db;
use frame\lib\VerfiyParam;

class Account extends Base
{
    public function index()
    {
        $data = Db::name('user')->where(['id' => $this->uid])->find();
        $this->view('index' , ['data' => $data]);
    }
    public function doEdit()
    {
        $param = $_POST;
        $data = Db::name('user')->where(['id' => $this->uid])->find();
        $rule = ['password|密码' => 'min:6|max:12|alphaNum' , 'email|邮箱' => 'email'];
        VerfiyParam::init($param , $rule);
        if(!empty($param['password']))
        {
            $pwd = encrypt_pwd($param['password']);
            if($data['password'] == $pwd) error('新密码不能与旧密码一致');
            $res = Db::name('user')->where(['id' => $this->uid])->update(['password' => $pwd]);
            $_SESSION['user'] = null;
            unset($_SESSION['user']);
            if($res) success();
            error();
        }
    }
  
}
